<?php echo $header; ?>
<div class="content" style="margin-left: 10px; margin-right: 10px;">
    <div class="warning"<?php if(!$error_warning): ?> style="display:none"<?php endif; ?>>
        <?php echo $error_warning; ?>
    </div>
    <div class="success"<?php if(!$success): ?> style="display:none"<?php endif; ?>>
        <?php echo $success; ?>
    </div>
    <h3><?php echo $partial_payment;  ?></h3>
    <form action="<?php echo $action; ?>" method="post">
        <table class="list">
            <thead>
            <tr>
                <td class="left"><?php echo $column_product; ?></td>
                <td class="left"><?php echo $column_model; ?></td>
                <td class="right"><?php echo $column_quantity; ?></td>
                <td class="right"><?php echo $column_price; ?></td>
                <td class="right"><?php echo $column_total; ?></td>
                <td class="right"><?php echo $column_payment; ?></td>
                <td class="right"><?php echo $column_paid; ?></td>
                <td class="right"><?php echo $column_status; ?></td>
            </tr>
            </thead>
            <tbody id="product">
            <tr id="product-row-<?php echo $product['order_product_id']; ?>">
                <td class="left"><?php echo $product['name']; ?></td>
                <td class="left"><?php echo $product['model']; ?></td>
                <td class="right"><input id="prod-partial-quantity-<?php echo $product['order_product_id']; ?>" type="text" name="quantity" value="<?php echo $product['quantity']; ?>" /></td>
                <td class="right" id="prod-partial-price-<?php echo $product['order_product_id']; ?>"><?php echo $product['price']; ?></td>
                <td id="prod-partial-total-<?php echo $product['order_product_id']; ?>" class="right"><?php echo $product['total']; ?></td>
                <td class="right">
                    <select name="payment">
                        <?php foreach($payments as $code=>$method): ?>
                        <option<?php if($code==$prodPayment): ?> selected="true"<?php endif; ?> value="<?php echo $code; ?>"><?php echo $method; ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
                <td><input type="text" name="money" value="<?php echo $product['money']; ?>" /></td>
                <td class="right">
                    <select name="status">
                        <?php foreach($product['status'] as $num=>$status): ?>
                        <option<?php if($num==$productStatus): ?> selected="true"<?php endif; ?> value="<?php echo $num; ?>"><?php echo $status; ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="center" colspan="9">
                    <a class="button" href="#" onclick=" return add_to_partial()"><?php echo $confirm; ?></a>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>

<script type="text/javascript">
    $('input[name=quantity]').live('change',function(){
        var id=$(this).attr('id').replace('prod-partial-quantity-','');
        //toFixed(3)
        var total=$(this).val()*$('#prod-partial-price-'+id).html();

        $('#prod-partial-total-'+id).html(total.toFixed(4));
    });

    function add_to_partial(){
        if($('input[type=text]').val()>0){
            var url=window.location.search.replace('quantity=','');
            var data=$('form').serialize();

            $.ajax({
                url: url.replace('add_to_partial','add_to_partial_ajax'),
                type: 'get',
                data: data,
                dataType: 'json',
                success: function(json){
                    if(json.error){
                        $('.warning').removeAttr('style');
                        $('.warning').html(json.error);
                    }
                    if(json.success){
                        $('.success').removeAttr('style');
                        $('.success').html(json.success);
                    }
                    if(json.result){
                        window.close();
                        window.opener.location.reload();
                    }
                }
            });
        }

        return false;
    }
</script>

<?php echo $footer; ?>